package com.pet.server.ext.action.square;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Image;
import com.pet.server.ext.data.Page;
import com.pet.server.ext.data.PetAdopt;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.cache.ConstantUtil;

public class Adoptlist extends ActionBase{

	public Integer startIndex,itemCount,user_id;
	public String queryString,cate;
	public Page page;
	public Adoptlist(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {
		parseToParameter(params);
		itemCount = p.itemCount==0?10:p.itemCount;
		page = new Page(p.startIndex, itemCount,p.queryString);
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		userService.searchPetAdopt(page, user.user_id, p.citycode, p.area,p.pet_cate,p.user_id);
	    JSONArray listJson = new JSONArray();
		for(PetAdopt pa:(List<PetAdopt>)page.getList()){
			JSONObject paJson=new JSONObject();
			paJson.accumulate("adopt_id", pa.adopt_id);
			paJson.accumulate("image",pa.ico_path);
			paJson.accumulate("brand",pa.breed);
			paJson.accumulate("brand_name",ConstantUtil.getName(pa.breed));
			paJson.accumulate("sex",pa.sex);
			listJson.add(paJson);
		}
		Result result = new Result();
        result.setPage4array(page, listJson);
	    return result;
	}


}
